package com.oreilly.ez.repo;

import com.oreilly.ez.entity.Account;
import com.oreilly.ez.entity.SysUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.web.bind.annotation.CrossOrigin;
//import org.springframework.data.rest.core.annotation.RestResource;


@RepositoryRestResource
@CrossOrigin
public interface AccountRepo extends JpaRepository<Account,Integer> {

//    @RestResource(path = "pin", rel = "pin")
//    SysUser findByPin(@Param("pin") String pin);


//    Page<?> findByUserPin(String pin, Pageable pageable);

    @RestResource(path = "by-pin")
    @Query(value = "select * from account  p " +
            "where p.user_pin = :pin order by p.account_date desc",
           countQuery = " select count(*) from account p where p.user_pin = :pin",
            nativeQuery = true)
    Page<?> byPin(@Param("pin") String pin, Pageable pageable);

}
